package zaijiansunwukong;

import zaijiansunwukong.util.FileUtil;
import zaijiansunwukong.util.ImageUtils;

/**
 * html转图片
 *
 * @author
 * @date 2024/11/26 14:07
 * @description: 详细说明
 */
public class HtmlToImage {
    public static void main(String[] args) {
         String htmlStr = "\t<div style=\"height: 500px;width: 500px;background: #aee0ff;\">\n" +
                "\t\t这个是一个div\n" +
                "\t\t<h1>标题</h1>\n" +
                "\t\t<ol>\n" +
                "\t\t\t<li>a</li>\n" +
                "\t\t</ol>\n" +
                "\t\t<img style=\"margin-left: 1500px;\" width=\"300px\" height=\"200px\" " +
                 "\t\t\t\t src=\"https://inews.gtimg.com/newsapp_bt/0/11911825373/1000\">\n" +
                "\t</div>";
        //方式1、直接写到本地
        String imagePath = "htmlToImage.png";
        ImageUtils.htmlToImage(htmlStr, imagePath);

        try {
            //方式2、先获取字节，再写
            byte[] bytes = ImageUtils.htmlToImage(htmlStr);
            FileUtil.localBufferWrite(bytes, "E:\\javaWorkspace\\freemarker-html2pdf\\freemarker-html2pdf\\htmlToImage2.png");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
